package org.micode.demo.web.controller;

import org.micode.common.annotation.NoNeedLogin;
import org.micode.common.domain.ApiResult;
import org.micode.common.helper.I18nMsgHelper;
import org.micode.demo.web.base.BaseWebAdminController;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.web.servlet.error.ErrorController;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/web-admin/auth")
public class AuthController
        extends BaseWebAdminController
        implements ErrorController {

    private static final String ERROR_PATH = "/error";

    @NoNeedLogin
    @PostMapping("/ok")
    public ApiResult<Boolean> ok() {
        return returnSuccess(true);
    }

    @NoNeedLogin
    @PostMapping("/invalidToken")
    public ApiResult<String> invalidToken() {
        return returnFailToken();
    }

    @NoNeedLogin
    @GetMapping("/invalidTokenForGet")
    public ApiResult<String> invalidTokenForGet() {
        return returnFailToken();
    }

    @NoNeedLogin
    @GetMapping("/error")
    public ApiResult<String> errorGet() {
        return returnFail(I18nMsgHelper.get("valid.api.not-found"));
    }

    @Override
    public String getErrorPath() {
        return "/web-admin/auth" + ERROR_PATH;
    }

}
